export function patch(oldVnode, vnode) {
    const isRealElement = oldVnode.nodeType;
    if(isRealElement) {
        const oldElm = oldVnode;
        const parentNode = oldElm.parentNode;
        let el = createElm(vnode);
        parentNode.insertBefore(el, oldElm.nextSibling);
        parentNode.removeChild(oldElm);
        return el;
    }
}

function createElm(vnode) {
    let {tag, data, children, text} = vnode;
    if(typeof tag === 'string') {
        vnode.el = document.createElement(tag);
        children.forEach(child => {
            vnode.el.appendChild(createElm(child));
        })
    } else {
        vnode.el = document.createTextNode(text);
    }
    return vnode.el;
}